home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mc51bugs.zip / Q29471 < prev    next >
Text File  |  1988-07-29  |  2KB  |  63 lines

  1. Q29471 Bad Code Generated with /Od and Ternary Operator
  2. C Compiler
  3. 5.00 5.10 | 5.10
  4. MS-DOS    | OS/2
  5.  
  6. Summary:
  7.    If the compiler generates incorrect code for evaluating ternary
  8. operators with optimization disabled, using /Ox corrects the problem.
  9.    This problem was limited to a very special case (described below)
  10. in which a while() statement makes calls to the toupper() macro using
  11. a register variable.
  12.    Microsoft has confirmed this to be a problem in Versions 5.00 and
  13. 5.10. We are researching this problem and will post new information as
  14. it becomes available.
  15.  
  16. More Information:
  17.     When compiled with /Od, the code is bad; when compiled with /Ox,
  18. the code is good.
  19.     The problem lies with the while() statement in function foo(). The
  20. problem only occurs if foo() has one register parameter.
  21.    If neither or both parameters are register variables, the problem
  22. ends. The problem also is dependent on having the two calls to
  23. toupper() and the && with ptr1[i]. (This is a very special-case
  24. problem.)
  25.    The following is a code demonstration of the problem:
  26.  
  27. #include <ctype.h>
  28. #include <stdio.h>
  29.  
  30. char one[] = "SKIP";
  31. char two[] = "SKIP";
  32.  
  33. void foo(char *ptr1, char **ptr2);
  34. void main(void);
  35.  
  36. void main(void)
  37. {
  38.     char *ptr1 = one;
  39.     char *ptr2 = two;
  40.     foo(ptr1, &ptr2);
  41.  
  42. }
  43.  
  44. void foo(char *ptr1, char register **ptr2)  /* register is needed */
  45. {                                           /* to force problem   */
  46.     int i = 0;
  47.  
  48.      /* here is the problem line... */
  49.     while((toupper(ptr1[i]) == toupper((*ptr2)[i])) && ptr1[i])
  50.         i++;
  51.  
  52.     if (i == 0)
  53.         printf("i is %d; bad code!\n", i);
  54.     else
  55.         printf("good code.\n");
  56.  
  57. }
  58.  
  59.  
  60.  
  61. Keywords:  buglist5.00 buglist5.10
  62. Updated  88/07/29 14:28
  63.